#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
  int opt;

  while((opt = getopt(argc,argv,"if:lr")) != -1)       
    {
      switch(opt){
      case 'i':
      case 'l':
      case 'r':
        printf("option: %c\n", opt);
        printf("option: %d\n", optind);
        break;
      case 'f':
        printf("filename: %s\n", optarg);
        printf("option: %d\n", optind);                   
        break;
      case ':':
        printf("option needs a value \n");
        printf("option: %d\n", optind);                   
        break;
      case '?':
        printf("unknown option: %c\n", optopt);
        printf("option: %d\n", optind);                   
        break;
      }
    }
  printf("After the switch optind: %d\n",optind);
  printf("After the switch argc: %d\n",argc);
  printf("After the switch argv: %s\n",argv[3]);
  for(; optind < argc; optind++)                      
    printf("argument: %s\n", argv[optind]);
  return 0;
}
